package com.deer.wms.company;


import com.baomidou.mybatisplus.generator.SimpleAutoGenerator;
import com.baomidou.mybatisplus.generator.config.*;
import com.baomidou.mybatisplus.generator.config.rules.DateType;
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;
import com.deer.wms.project.root.core.service.AbstractService;
import com.deer.wms.project.root.core.service.Service;
import com.deer.wms.project.root.model.BaseEntity;

/**
 * @author : wei
 * @since : 2021-07-23 14:08:13
 **/
public class CodeGenerator {

    public static void main(String[] args) {
        new SimpleAutoGenerator() {
            /**
             * 全局配置Builder
             */
            @Override
            public IConfigBuilder<GlobalConfig> globalConfigBuilder () {
                String projectPath = System.getProperty("user.dir");
                projectPath += "/wms-company/src/main/java";
                if(false){
                    System.out.println(projectPath);
                    throw new RuntimeException("xxx");
                }
                return new GlobalConfig.Builder()
                        .openDir(false)  //是否打开输出目录
                        .outputDir(projectPath)   //生成文件的输出目录【 windows:D:// linux or mac:/tmp 】
                        .fileOverride()  //覆盖已有文件，默认true
                        .enableSwagger() //开启 swagger 模式
                        .author("wei")      //开发人员
                        .dateType(DateType.TIME_PACK) //时间类型对应策略
                        .commentDate("yyyy-MM-dd");   //注释日期 格式
            }

            /**
             * 数据源配置
             */
            @Override
            public IConfigBuilder<DataSourceConfig> dataSourceConfigBuilder () {
                return new DataSourceConfig.Builder(
                        "jdbc:mysql://localhost:3306/new_wms?useUnicode=true&characterEncoding=UTF-8&allowMultiQueries=true&useSSL=false&serverTimezone=UTC",
                        "root",
                        "123456"
                );
            }

            /**
             * 代码生成策略配置
             */
            @Override
            public IConfigBuilder<StrategyConfig> strategyConfigBuilder () {
                return new StrategyConfig.Builder()
                        .enableCapitalMode()
                        .enableSkipView()
                        .addTablePrefix("co_")     //表前缀
                        .addInclude("co_company")  //表明
                        .entityBuilder()
                        .superClass(BaseEntity.class)
                        .enableSerialVersionUID()
                        .enableChainModel()
                        .enableLombok()
                        .naming(NamingStrategy.underline_to_camel)
                        .mapperBuilder()
                        .formatMapperFileName("%sMapper")
                        .formatXmlFileName("%sMapper")
                        .enableBaseResultMap()
                        .serviceBuilder()
                        .superServiceClass(Service.class)
                        .superServiceImplClass(AbstractService.class)
                        .formatServiceFileName("%sService")
                        .formatServiceImplFileName("%sServiceImpl")
                        .controllerBuilder()
                        .formatFileName("%sController")
                        .enableRestStyle()
                        .enableHyphenStyle();
            }

            @Override
            public IConfigBuilder<PackageConfig> packageConfigBuilder () {
                return new PackageConfig.Builder()
                        .parent("com.deer.wms.company")
                        .entity("model")
                        .mapper("mapper")
                        .service("service")
                        .serviceImpl("service.impl")
                        .controller("web")
                        .xml("dao.xml");
            }
        }.execute();
    }
}
